#!/usr/bin/env python
import os
import sys
from app import create_app
from app.utils.db_utils import init_db
from app.utils.data_utils import init_test_data
from app.models.mysql_db import db

app = create_app()

if __name__ == '__main__':
    if len(sys.argv) > 1:
        command = sys.argv[1]
        
        if command == 'init_db':
            # 初始化数据库
            with app.app_context():
                init_db(app)
        elif command == 'init_data':
            # 初始化测试数据
            init_test_data(app)
        elif command == 'run':
            # 运行应用
            app.run(debug=True, host='0.0.0.0', port=5000)
        else:
            print(f"未知命令: {command}")
            print("可用命令: init_db, init_data, run")
    else:
        # 默认运行应用
        app.run(debug=True, host='0.0.0.0', port=5000)